require('dotenv').config();
const { Sequelize } = require('sequelize');

const config = {
  host: process.env.DB_HOST || 'localhost',
  port: process.env.DB_PORT || 3306,
  database: process.env.DB_NAME || 'yundayin',
  username: process.env.DB_USER || 'root',
  password: process.env.DB_PASSWORD || '',
  dialect: 'mysql',
  dialectOptions: {
    charset: 'utf8mb4',
    collate: 'utf8mb4_unicode_ci',
    dateStrings: true,
    typeCast: true
  },
  timezone: '+08:00',
  logging: process.env.NODE_ENV === 'development' ? console.log : false
};

const sequelize = new Sequelize(config.database, config.username, config.password, config);

module.exports = sequelize;